﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tec2.GUI.Controller;
using TecBaseObjects.Objects;

namespace Tec2.GUI.Dialog {
    public partial class ProjectCaseContactsForm : Form {

        #region Members

        private ProjectCaseContactsController controller;
        private int myProjectID;
        private ProjectCaseObject myModel;
        private Boolean cancel = true;

        #endregion

        #region Constructor

        public ProjectCaseContactsForm(int projectID) {

            InitializeComponent();
            this.myProjectID = projectID;
            this.controller = new ProjectCaseContactsController(this);
            this.controller.LoadModels();
            SetFormEventHandler();
            SetFormDataSources();
        }

        #endregion

        #region Properties

        public Boolean Cancel {
            get { return this.cancel; }
            set { this.cancel = value; }
        }

        public ProjectCaseObject MyModel {
            get { return this.myModel; }
            set { this.myModel = value; }
        }

        public int MyProjectID {
            get { return this.myProjectID; }
        }

        #endregion

        #region Methods

        public void SetFormDataSources() {
            int anz = 1;
            int durchlauf = 1;
            foreach(ProjectContactObject con in this.MyModel.MyContacts) {
                if(anz == durchlauf) {
                    con.Selected = true;
                    durchlauf += 1;
                }
            }

            this.bsProjectCase.DataSource = this.MyModel;
            this.bsContacts.DataSource = this.MyModel.MyContacts;

        }

        private void SetFormEventHandler() {
            this.btnOK.Click += new EventHandler(this.controller.ButtonOK);
            this.btnCancel.Click += new EventHandler(this.controller.ButtonCancel);
        }

        #endregion

    }
}
